exports.mongoose = () => {
  const mongoose = require("mongoose");

  //创建连接
  mongoose.connect("mongodb://localhost:27017/koa", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  });

  //创建规则
  const Schema = new mongoose.Schema({
    name: {
      type: "String",
      default: "zs",
    },
    age: {
      type: "Number",
      default: 100,
    },
  });

  //创建表
  const mydemo = mongoose.model("demo", Schema);

  //新增
  //   mydemo.create({ name: "ww" }, { name: "ls" }).then((res) => console.log(res));

  //查询所偶
  // mydemo.find().then((res) => console.log(res));

  //查询多个
  mydemo.find({ name: "ww" }).then((res) => console.log(res));

  //查询单个
  //   mydemo
  //     .findOne({ _id: "612c9ec9903b7116b88815e1" })
  //     .then((res) => console.log(res));

  //删除单个
  //   mydemo.deleteOne().then((res) => console.log(res));

  //
};
